package com.jiawei.队列.增强队列;

import com.jiawei.链表.LinkedList;
import com.jiawei.链表.单链表.LinkedListSingle;


/**
 * @author : willian fu
 * @version : 1.0
 */
public class ExpandLinkedListQueue<E> implements ExpandQueue<E>{

    //订阅者
    private LinkedList<Subscribe> subscriber;

    //队列
    private LinkedList<E> queue;

    public ExpandLinkedListQueue() {
        this.subscriber = new LinkedListSingle<>();
        this.queue = new LinkedListSingle<>();
    }

    public ExpandLinkedListQueue(LinkedList queue) {
        new ExpandLinkedListQueue(new LinkedListSingle<>(), queue);
    }

    public ExpandLinkedListQueue(LinkedList<Subscribe> subscriber, LinkedList<E> queue) {
        this.subscriber = subscriber;
        this.queue = queue;

    }

    /**
     * 添加一个订阅者
     *
     * @param subscribe 订阅
     * @return
     */
    @Override
    public boolean subscribe(Subscribe<? extends E> subscribe) {
        subscriber.add(subscribe);
        return true;
    }

    /**
     * 发布事件
     *
     * @param subscribe
     */
    @Override
    public void publish(Subscribe subscribe) {
        subscriber.forEach(val -> subscribe.subscribe(val));
    }

    /**
     * 设置消费速率
     *
     * @param rate
     */
    @Override
    public void setRate(int rate) {
        //this.rate = rate;
    }

    /**
     * 获取队列头部元素，获取后会删除该元素
     *
     * @return 值
     */
    @Override
    public E get() {
        return null;
    }

    /**
     * 添加一个元素到队列
     *
     * @param val 值
     * @return 添加结果
     */
    @Override
    public boolean add(E val) {
        return false;
    }

    /**
     * 获取队列长度
     *
     * @return 长度
     */
    @Override
    public int length() {
        return 0;
    }

    @Override
    public void print() {

    }

}
